#include <sqlite3.h>
#include <iostream>
#include <stdlib.h>
#include "../pojo/user.h"
#include "SQL.h"
using namespace std;
namespace iceBear
{
    SQL::SQL(/* args */)
    {
        // 数据库初始化
        flag = 0;
        isOpen = 1;
        flag = sqlite3_open("../database/my.db", &db);
        if (flag != SQLITE_OK)
        {
            cout << "打开数据库错误 错误码" << sqlite3_errstr(flag);
            isOpen = -1;
        }
        cout << "打开数据库完成\n";
        flag = 0;
        flag = sqlite3_exec(db, "create table student(id char,name char, password char);", NULL, NULL, &err_msg);
        if (flag != SQLITE_OK)
        {
            cout << "创建数据表失败，由于" << err_msg;
            isOpen = -1;
        }
    }

    SQL::~SQL()
    {
    }
    User SQL::selectUserById(int id)
    {
        if (isOpen == 0)
        {
            return User("NULL");
        }
        sprintf(sql, "select * from student where id='%s'';", id);
        flag = 0;
        flag = sqlite3_exec(db, sql, select_callback, (void *)&flag, &err_msg);
        if (flag != SQLITE_OK)
        {
            cout << "查询错误" << err_msg;
            return User("NULL");
        }
    }



}

int select_callback(void *data, int argc, char **value, char **name)
{
    User user;
    user
    *(int *)data = 1;
    return 0;
}